//
//  PurchaseInfoCell.m
//  yigou
//
//  Created by wangdianlei on 2017/1/13.
//  Copyright © 2017年 hanyiwang. All rights reserved.
//

#import "PurchaseInfoCell.h"

@implementation PurchaseInfoCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [self.ptype.layer setBorderWidth:1];
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref = CGColorCreate(colorSpace, (CGFloat[]){0.05, 0.63, 0.71, 1});
    [self.ptype.layer setBorderColor:colorref];
    CGColorRelease(colorref);
    CGColorSpaceRelease(colorSpace);
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 150 - 1, ScreenWidth, 1 )];
    line.backgroundColor = LineColor;
    [self.contentView addSubview:line];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)fillWithData:(MMMarketNew *)data {
    self.title.text = data.goods_name;
    self.position.text = data.goods_addr;
    self.price.text = [NSString stringWithFormat:@"¥%@", data.market_price];;
    NSString *imgurl = @"";
    imgurl = data.goods_pic_url;
    NSArray *array = [data.goods_pic_url componentsSeparatedByString:@","];
    if (array.count > 0) {
        imgurl = array[0];
    }
    [self.img sd_setImageWithURL:[NSURL URLWithString:imgurl] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
}

- (IBAction)clickMin:(id)sender {
    if ([DataCenter sharedDataCenter].purchaseCount > 0) {
        [DataCenter sharedDataCenter].purchaseCount -= 1;
        self.count.text = [NSString stringWithFormat:@"%ld", [DataCenter sharedDataCenter].purchaseCount];
        self.totalcount.text = [NSString stringWithFormat:@"共计%ld件商品", [DataCenter sharedDataCenter].purchaseCount];
        [[NSNotificationCenter defaultCenter] postNotificationName:POST_UPDATEP object:nil];
    }
}

- (IBAction)clickPlus:(id)sender {
    [DataCenter sharedDataCenter].purchaseCount += 1;
    self.count.text = [NSString stringWithFormat:@"%ld", [DataCenter sharedDataCenter].purchaseCount];
    self.totalcount.text = [NSString stringWithFormat:@"共计%ld件商品", [DataCenter sharedDataCenter].purchaseCount];
    [[NSNotificationCenter defaultCenter] postNotificationName:POST_UPDATEP object:nil];
}



@end
